#ifndef SERVER_H_H
#define SERVER_H_H

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <signal.h>
#include <sqlite3.h>
#include <sys/wait.h>
#include <time.h>
#include <pthread.h>

#define R 1 //注册
#define L 2 //登录
#define S 3 //查询
#define H 4 //历史

#define DBNAME "stu.db"

#define ERRLOG(errmsg) do{\
                                                            perror(errmsg);\
                                                            printf("file:%s,func:%s,line:%d\n",__FILE__,__func__,__LINE__);\
                                                            exit(-1);\
                                                            }while(0);

struct client{
    int acceptfd;
    sqlite3* db;
};

typedef struct{
    int type;
    char name[32];
    char pass[32];
    char text[256];
}MSG;

void handler();

void do_client(int acceptfd,sqlite3* db);

void do_register(int acceptfd,MSG* msg,sqlite3* db);

void do_login(int acceptfd,MSG* msg,sqlite3* db);

void do_select(int acceptfd,MSG* msg,sqlite3* db);

int do_searchword(int acceptfd,MSG* msg,char word[]);

void do_time(char Time[]);

void do_history(int acceptfd,MSG* msg,sqlite3* db);

int history_callback(void* arg,int ncolumn,char** values,char** name);

void* pthread_client(void* arg);

#endif